//
//  LGMainViewController.swift
//  LGWeibo
//
//  Created by 李更 on 8/9/16.
//  Copyright © 2016 itcast. All rights reserved.
//

import UIKit

class LGMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        
        
        //实例化tabbar
        let tabBar = LGTabBar()
        
        //设置代理
        tabBar.LGDelegate = self
        
        //通过Kvc给只读属性传值
        setValue(tabBar, forKey: "tabBar")
        
        
        
        
        //首页
        addChildViewController(LGHomeViewController(), imageName: "tabbar_home", title: "首页")
        //信息
        addChildViewController(LGMessageViewController(), imageName: "tabbar_message_center", title: "消息")
        //发现
        addChildViewController(LGDiscoverViewController(), imageName: "tabbar_discover", title: "发现")
        //我
        addChildViewController(LGProfileViewController(), imageName: "tabbar_profile", title: "我")
    }
    
    func addChildViewController(vc : UIViewController , imageName : String , title : String)  {
        vc.navigationItem.title = title
        vc.tabBarItem.title = title
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orangeColor()], forState: UIControlState.Selected)
        
        vc.tabBarItem.image = UIImage(named: imageName)
        
        vc.tabBarItem.selectedImage = UIImage(named: "\(imageName)_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        
        addChildViewController(UINavigationController(rootViewController: vc))
        
        
    }
    

}

extension LGMainViewController : LGTabBarDelegate {
    func tabBarButtonClick() {
        print("撰写按钮被点了")
    }
    
}
